<?php
/* @var $nav \frontend\modules\yii\models\FrameNavs */

use frontend\modules\yii\models\FrameNavs;
use yii\web\View;

echo \yii\helpers\Html::tag("h3", "Header Nav:", ["style" => "color:#ccc; border-bottom: 1px solid #ccc"]);

echo \yii\bootstrap\NavBar::widget([
    'options' => [
        'style' => "background-color:#2697ed; border-radius: 10px; "
    ],
    'headerContent' => \yii\bootstrap\Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-left'],
        'items' => array_map(function($item) use($nav){
            return ["label" => $item["label"], "url" => ["nav", "nav" => $item["id"]], "options" => ["class" => $item["id"] == $nav->id ? "active" : ""]];
        }, FrameNavs::find()->where(["location" => "head"])->asArray()->all()),
    ])
]);
echo \yii\helpers\Html::a("Create", ["nav"], ['class' => 'btn btn-success', "style" => "margin-right:10px"]);
$form = \yii\widgets\ActiveForm::begin(['id' => 'nav-form']);
echo $form->field($nav, "label")->textInput(['autofocus' => true]);
echo $form->field($nav, "location")->label(false)->hiddenInput(["value" => "head"]);
echo $form->field($nav, "url")->textInput();
echo \yii\helpers\Html::submitButton('Save', ['class' => 'btn btn-primary', 'name' => 'Save', "style" => "margin-right:10px"]);
if ($nav->id){
    $hasAhead = FrameNavs::find()->where(["location" => "head"])->andWhere(["<", "id", $nav->id])->exists();
    if ($hasAhead) echo \yii\helpers\Html::a("Move Ahead", ["nav", "move" => "ahead", "id" => $nav->id], ['class' => 'btn btn-primary', "style" => "margin-right:10px"]);
    $hasBehind = FrameNavs::find()->where(["location" => "head"])->andWhere([">", "id", $nav->id])->exists();
    if ($hasBehind) echo \yii\helpers\Html::a("Move Behind", ["nav", "move" => "behind", "id" => $nav->id], ['class' => 'btn btn-primary', "style" => "margin-right:10px"]);
}
\yii\widgets\ActiveForm::end();

$js = <<< JS
function clickNav(navId){
    $.ajax({
        type: "POST",
        url: "nav",
        data: {
            nav: navId
        },
        success: function(res){
            console.info(res);
        }
    });
    return false;
}
function ahead(){
    
}
JS;

$this->registerJs($js, View::POS_HEAD, "nav-click-key");
